package com.sensePlusVR.bean;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import com.sensePlusVR.application.VRApplication;
import com.sensePlusVR.utils.MyLog;

import org.xutils.DbManager;
import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

/**
 * 
 * @author: Loren
 * @create: 2016-10-31下午3:03:35
 * @desc:获取某游戏被所有用户赞的次数及是否被当前用户赞过 
 *
 */
@Table(name = "CommendItem")
public class CommendItem implements Parcelable{
	private static final String TAG = CommendItem.class.getSimpleName();
	
	@Column(name = "id",isId = true,autoGen = false)
	private int id;
	
	@Column(name = "userAction")
	private int userAction;
	
	@Column(name = "down")
	private int down;
	
	@Column(name = "up")
	private int up;
	
	public int getId() {
		return id;
	}
	public void setId(int Id) {
		this.id = Id;
	}
	
	public int getUserAction() {
		return userAction;
	}
	public void setUserAction(int userAction) {
		this.userAction = userAction;
	}
	public int getDown() {
		return down;
	}
	public void setDown(int down) {
		this.down = down;
	}
	public int getUp() {
		return up;
	}
	public void setUp(int up) {
		this.up = up;
	}
	
	
	
	public CommendItem() {}
	
	public CommendItem(Parcel in){
		id = in.readInt();
		userAction = in.readInt();
		down = in.readInt();
		up = in.readInt();
	}
	
	
	
	public static void saveOrUpdate(Object object) {
		try {
    		Context context = VRApplication.getAppContext();
    		if(context != null) {
    			DbManager db = VRApplication.getDbManager();
    			db.saveOrUpdate(object);
    		}
    	}catch(Exception e){
    		MyLog.e(TAG, "CommendItem update failed: "+e);
    	}
	}
	
	public static CommendItem getCommendItembyId(int gameId){
		try {
    		Context context = VRApplication.getAppContext();
    		if(context != null) {
    			DbManager db = VRApplication.getDbManager();
    			return db.selector(CommendItem.class).where("id", "=", gameId).findFirst();
    		}
    	}catch(Exception e){
    		MyLog.e(TAG, "CommendItem update failed: "+e);
    	}
		return null;
	}
	
	@Override
	public String toString() {
		return "CommendItem [id=" + id + ", userAction=" + userAction + ", down=" + down
				+ ", up=" + up + "]";
	}
	
	@Override
	public int describeContents() {
		return 0;
	}
	
	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(id);
		out.writeInt(userAction);
		out.writeInt(down);
		out.writeInt(up);
	}
	
	public static final Creator<CommendItem> CREATOR = new Creator<CommendItem>() {

		@Override
		public CommendItem createFromParcel(Parcel in) {
			return new CommendItem(in);
		}

		@Override
		public CommendItem[] newArray(int size) {
			return new CommendItem[size];
		}
	};
	
	
}
